//
//  SNMainHomePageCollectionViewCell.m
//  project
//
//  Created by 黄建华 on 2020/10/27.
//  Copyright © 2020 黄建华. All rights reserved.
//

#import "SNMainHomePageCollectionViewCell.h"

@implementation SNMainHomePageCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _bgView = [UIView new];
        [self addSubview:_bgView];
    }
    return self;
}

- (void)configWithModel:(SNHomeModel *)model edit:(BOOL)edit {
    self.backgroundColor = [UIColor clearColor];
    
    [_bgView removeAllSubviews];
    _bgView.frame               = SNFRAME(10, 5, screenWidth-20,70+2.5);
    
    
    _bgView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    _bgView.layer.cornerRadius = 6;
//    _bgView.backgroundColor     = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
//    _bgView.layer.shadowColor   = [UIColor colorWithRed:0/255.0 green:68/255.0 blue:131/255.0 alpha:0.11].CGColor;
//    _bgView.layer.shadowOffset  = CGSizeMake(0, 1);
//    _bgView.layer.shadowOpacity = 1;
//    _bgView.layer.shadowRadius  = 8;
//    _bgView.layer.cornerRadius  = 5;

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:SNFRAME(15, 16, 38, 38)];
    imageView.image = [UIImage image:model.imageName];
    [_bgView addSubview:imageView];

    UILabel *titleLabel = [UILabel simpleWithRect:SNFRAME(_bgView.width-110-28, 27, 110, 20) withAlignment:NSTextAlignmentRight withFontSize:14 withText:model.functionTitle withTextColor:[UIColor blackColor]];
    titleLabel.textColor = UIColorHEX(0x96969F);
    titleLabel.font                      = SNFONTREGULAR(12);
    titleLabel.adjustsFontSizeToFitWidth = YES;
    [_bgView addSubview:titleLabel];
    
    UIImageView *right = [[UIImageView alloc] initWithFrame:SNFRAME(titleLabel.right +3, 25, 14, 24)];
    right.image = [UIImage imageNamed:@"next"];
    [_bgView addSubview:right];

    UILabel *valuelabel = [UILabel simpleWithRect:SNFRAME(imageView.right+13,17, _bgView.width - 70 -120, 22) withAlignment:NSTextAlignmentLeft withFontSize:20 withText:model.value withTextColor:[UIColor blackColor]];
    valuelabel.adjustsFontSizeToFitWidth = YES;
    [_bgView addSubview:valuelabel];
    valuelabel.textColor = UIColorHEX(0x161616);
    valuelabel.font = SNFONTMEDIUM(18);
    
    UILabel *valueAvelabel = [UILabel simpleWithRect:SNFRAME(imageView.right+13,39, _bgView.width - 70 -120, 18) withAlignment:NSTextAlignmentLeft withFontSize:20 withText:model.valueDes withTextColor:[UIColor blackColor]];
    valueAvelabel.adjustsFontSizeToFitWidth = YES;
    [_bgView addSubview:valueAvelabel];
    valueAvelabel.font      = SNFONTREGULAR(10);
    valueAvelabel.textColor = [UIColor colorFromHex:0x424242];

    int tag = model.tag;
//    NSLog(@"🙂>>>>%@ %d",model.functionTitle,model.tag);
    if (tag == 1) {
        [valuelabel setAttributedText:[SN_PublicClass label1With:valuelabel.text withFontsize:10.0 withChangeText1:SN_Text(@"h") withChangeText2:SN_Text(@"mins")]];
    }
    
    if (tag == 3) {
        NSString *vvvvv = [getChectkLast getObjectValue];
        if (vvvvv == nil) {
            vvvvv = [NSString stringWithFormat:@"%@:%@",SN_Text333(@"上一次"),[[NSDate date]dateToString]];
            valueAvelabel.text = vvvvv;
        }
//        valuelabel.text = @"GET";
        valuelabel.text = @"s-Band";
    }
    
    if (tag == 4) {
        [valuelabel setAttributedText:[SN_PublicClass label1With:valuelabel.text withFontsize:10.0 withChangeText1:@"" withChangeText2:@"bpm"]];
    }
    if (tag == 5) {
        [valuelabel setAttributedText:[SN_PublicClass label1With:valuelabel.text withFontsize:10.0 withChangeText1:@"" withChangeText2:@"mmHg"]];
    }
    if (tag == 2) {
        valueAvelabel.text = model.valueDes;
        if (![model.hrAvg isEqualToString:@""]) {
            valueAvelabel.text = [model.hrAvg stringByAppendingString:@"bpm"];
        } else {
            valuelabel.text    = @"0 bpm";
            valueAvelabel.text = SN_Text(@"暂无数据");
        }
        if ([valuelabel.text containsString:@"bpm"]) {
            [valuelabel setAttributedText:[SN_PublicClass label1With:valuelabel.text withFontsize:10.0 withChangeText1:@"" withChangeText2:@"bpm"]];
        }
    }
}

@end
